package com.xhl.oauth2.config.oauth2;

import com.xhl.oauth2.base.R;
import com.xhl.oauth2.base.constant.ResponseConstant;
import com.xhl.oauth2.base.utils.ServletUtil;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@Component("restAuthenticationEntryPoint")
public class RestAuthenticationEntryPoint implements AuthenticationEntryPoint {

    //返回未得到授权时的报错:对应:invalid_token
    @Override
    public void commence(
            HttpServletRequest request,
            HttpServletResponse response,
            AuthenticationException authException) throws IOException {
        ServletUtil.printRestResult(R.error(ResponseConstant.OAUTH2_401.getCode(),ResponseConstant.OAUTH2_401.getMsg()));
    }
}
